﻿namespace Ulid;

/// <summary>
/// 一种用于 ULID随机部分的简单随机数生成器
/// </summary>
public class SimpleUlidRng : BaseUlidRng
{
    public override byte[] GetRandomBytes(DateTimeOffset dateTime)
    {
        var _buffer = new byte[RANDLEN];
        Random.Shared.NextBytes(_buffer);
        return _buffer;
    }

    public override void GetRandomBytes(Span<byte> buffer, DateTimeOffset dateTime)
    {
        if (buffer.Length < RANDLEN)
        {
            Throw(buffer.Length);
            static void Throw(int len) => throw new ArgumentException($"The given buffer must be at least {RANDLEN} bytes long, actual: {len}");
        }

        Random.Shared.NextBytes(buffer);
    }
}
